﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Xamarin.Forms;

namespace AppBlank.ViewModels
{
    public class ListViewDemoViewModel : BaseViewModel
    {
        Services.IDataServices Services = new Services.ListViewDemoService();

        public ObservableCollection<Models.MeiZiTuFuLi> meiZiTuFuLi { get; set; }
        public ObservableCollection<View> views { get; set; }

        public ListViewDemoViewModel()
        {
            Title = "App One";
            meiZiTuFuLi = new ObservableCollection<Models.MeiZiTuFuLi>();
            views = new ObservableCollection<View>();
            var list = Services.GetMeiZiTuFuLi();
            if (list != null) {
                foreach (var item in list)
                {
                    views.Add(new Pages.ItemImageView(item));
                    meiZiTuFuLi.Add(item);
                }

            }
           
            MessagingCenter.Subscribe<Pages.ListViewDemo>(this, "LoadFuliList", (obj) =>
             {
                 //  meiZiTuFuLi.AddRange(Services.GetMeiZiTuFuLi());
                   list = Services.GetMeiZiTuFuLi();

                 if (list != null) { 
                     foreach (var item in list)
                     {
                         views.Add(new Pages.ItemImageView(item));
                         meiZiTuFuLi.Add(item);
                     }
                 }
               
             });

        }



        // void

    }
}
